Skip to content

Conversation

@potrue
Copy link
Owner

@potrue potrue commented Aug 7, 2025

if (words.contains(word)) {
breakable_indexes.push_back(index);
break;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

自分だったら以下のような変数名にします。

        for (int end = 1; end <= s.size(); ++end) {
            for (int start : breakable_indexes) {
                string_view sub_str = s_view.substr(start, end - start);
                if (words.contains(sub_str)) {

while (!index_to_check.empty()) {
int index = index_to_check.front();
index_to_check.pop();
for (int i = 1; i <= s.size() - index; ++i) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここの i は word_length もしくは sub_str_length かなと思いました。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

たしかにそちらのほうがだいぶ分かりやすくなりますね!

public:
bool wordBreak(string s, vector<string>& wordDict) {
unordered_set<string> words(wordDict.begin(), wordDict.end());
unordered_set<int> visited;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

型で分かると言えば分かるのですが、 visited_indices の命名とかの方がよりわかりやすいと思います。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants